package com.xiaoxin.controller;

import com.xiaoxin.model.vo.PageResult;
import com.xiaoxin.model.vo.SettingsVo;
import com.xiaoxin.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author xiaoxiaode
 * @date 2021-08-30-19:47
 **/

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    // 查询通用设置
    @GetMapping("/settings")
    public ResponseEntity setting() {
        SettingsVo vo = settingsService.setting();
        return ResponseEntity.ok(vo);
    }

    // 设置陌生人问题
    @PostMapping("/questions")
    public ResponseEntity question(@RequestBody Map map) {
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    // 通知设置
    @PostMapping("/notifications/setting")
    public ResponseEntity notification(@RequestBody Map map) {
        System.out.println(settingsService);
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }

    // 分页查询黑名单
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        PageResult pageResult = settingsService.blacklist(page, size);
        return ResponseEntity.ok(pageResult);
    }

    // 取消黑名单
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long uid) {
        settingsService.deleteBlackList(uid);
        return ResponseEntity.ok(null);
    }
}
